/**
 *
 * Copyright (c) 2014 BinKylin Studio.
 *
 * Author: TBinkylin
 * Created Date: 2014-03-01
 * 
 * 	version					author					remark
 * 	1.0						benoit				
 */
package net.binkylin.common.utils;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DatabaseUtil {
	private static final Logger log = LoggerFactory.getLogger(DatabaseUtil.class);

	private static Map<String, String> sqlTypesMap = new HashMap<String, String>();

	static {
		Field[] fields = java.sql.Types.class.getDeclaredFields();
		for (Field item : fields) {
			try {
				String name = item.getName();
				String value = item.get(java.sql.Types.class).toString();

				log.debug("value===name: " + value + "===" + name);
				sqlTypesMap.put(value, name);
			} catch (IllegalArgumentException e) {
				log.error("[MPA] error occurred: IllegalArgumentException", e);
			} catch (IllegalAccessException e) {
				log.error("[MPA] error occurred: IllegalAccessException", e);
			}
		}
	}

	public static String getJDBCType(int type) {
		return sqlTypesMap.get(type + "");
	}

}
